/**
*  @author: yaoyuan
*  Description: Routes Index
*  created: 2015.04.08
**/
import {Router} from 'express';
import domain from 'domain';

//import interceptor from './interceptor';
let router = Router();

router.use((req, res, next) => {
	let _d = domain.create();
	/** 
	 json = interceptor(req);
	    if(!json.is) {
	    	return res.redirect(json.redirect);
	    }
	**/
	_d.on('error', (err) => {
		console.error('uncaughtException url=%s, msg=%s', req.url, err.stack || err.message || err);
	    if (!res.finished) {
	      res.statusCode = 500;
	      res.setHeader('content-type', 'application/json; charset=UTF-8');
	      res.end('uncaughtException');
	    }
	});
	_d.add(req);
	_d.add(res);
	_d.run(next);
});
// load controllers
//_U.router.loadControll(_U.relPath, _U.config.servlet).init();
//_U.initFiter({relPath: _U.relPath, config: _U.config, router: router});
_U.initRouter({relPath: _U.relPath, config: _U.config, router: router});


// catch 404 and forward to error handler
router.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// production error handler
// no stacktraces leaked to user
router.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});

export default router;
/**
			  (路由配置初始化)
用户请求--->>  路由匹配 --->> 数据过滤(vo->entriy) --->>


**/